// tools
import { initCpt } from '@/libs/vueTools';
import Vue from 'vue'
import MToast from './MToast.vue';

// 定义插件对象


const currentMsg = (options) => {
  if (Vue.prototype.$isServer) return;
  // 初始化构建实例
  let instance = initCpt(Vue, MToast);
  // 判断options
  if (typeof options === 'string') {
    instance.msg = options;
  } else if (typeof options === 'object') {
    Object.assign(instance, options);
  }
  // 显示toast
  instance.visible = true;
  console.log(instance)
  return instance;
}
// // 构建状态方法
['success', 'warning', 'info', 'error'].forEach(type => {
  currentMsg[type] = options => {
    if (typeof options === 'string') {
      options = {
        msg: options
      };
    }
    options.type = type;
    return currentMsg(options)
  };
});

export default currentMsg;

